package com.vader.admin.controller;

import com.vader.admin.entity.DO.BaseTaskRecord;
import com.vader.admin.entity.Query.BaseTaskRecordQuery;
import com.vader.admin.service.BaseTaskRecordService;
import com.vader.common.entity.CommonResponse;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.vader.common.entity.CommonResponse.*;

/**
 * 活动参加记录表(BaseTaskRecord)表控制层
 *
 * @author Vader
 * @since 2021-10-06 12:46:39
 */
@RestController
@RequestMapping("baseTaskRecord")
public class BaseTaskRecordController {
    /**
     * 服务对象
     */
    @Resource
    private BaseTaskRecordService baseTaskRecordService;

    /**
     * 分页查询
     *
     * @param baseTaskRecord 筛选条件
     * @param pageRequest    分页对象
     * @return 查询结果
     */
    @GetMapping
    public CommonResponse<Page<BaseTaskRecord>> queryByPage(BaseTaskRecord baseTaskRecord, PageRequest pageRequest) {
        return success(this.baseTaskRecordService.queryByPage(baseTaskRecord, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public CommonResponse<BaseTaskRecord> queryById(@PathVariable("id") Long id) {
        return success(this.baseTaskRecordService.queryById(id));
    }

    /**
     * 用户报名
     *
     * @param baseTaskRecordQuery 实体
     * @return 新增结果
     */
    @PostMapping("/joinTask")
    public CommonResponse<BaseTaskRecord> joinTask(@RequestBody BaseTaskRecordQuery baseTaskRecordQuery) {
        BaseTaskRecord baseTaskRecord = BaseTaskRecord.from(baseTaskRecordQuery);
        return success(this.baseTaskRecordService.insert(baseTaskRecord));
    }

    /**
     * 批量导入活动用户
     *
     * @param baseTaskRecordQuery 实体
     * @return 新增结果
     */
    @PostMapping("/batchJoinTask")
    public CommonResponse<BaseTaskRecord> batchJoinTask(@RequestBody BaseTaskRecordQuery baseTaskRecordQuery) {
        BaseTaskRecord baseTaskRecord = BaseTaskRecord.from(baseTaskRecordQuery);
        return success(this.baseTaskRecordService.insert(baseTaskRecord));
    }

    /**
     * 编辑数据
     *
     * @param baseTaskRecord 实体
     * @return 编辑结果
     */
    @PutMapping
    public CommonResponse<BaseTaskRecord> edit(@RequestBody BaseTaskRecord baseTaskRecord) {
        return success(this.baseTaskRecordService.update(baseTaskRecord));
    }

    /**
     * 取消报名
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public CommonResponse<Boolean> deleteById(Long id) {
        return success(this.baseTaskRecordService.deleteById(id));
    }

}

